#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;


//http://oj33.cn/contest.php?cid=1075
int n;
int Array[10];
int used[10];
void print()
{
	for (int i =1; i <=n; i++)
		printf("%d ", Array[i]);
	cout << endl;
}
void dfs(int k)
{

	for (int i = 0; i < n; i++)
	{
		if (!used[i])
		{
			used[i] = 1;
			Array[k] = i+1;
		
		if (k == n)print();
		else dfs(k + 1);
		used[i] = 0;
	}
	}
}
int main()
{
	cin >> n;
	dfs(1);
	return 0;
}